package org.mspring.mlog.service;

import org.mspring.mlog.dao.RoleEntityDao;
import org.mspring.mlog.entity.RoleEntity;
import org.mspring.nbee.common.PageResult;
import org.mspring.nbee.db.dao.sql.builder.part.condition.SqlCondition;
import org.mspring.nbee.db.dao.sql.pager.SqlPager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Gao Youbo
 * @since 2014-09-10 12:44:48
 */
@Service
public class RoleEntityService {

    private static final Logger LOG = LoggerFactory.getLogger(RoleEntityService.class);

    private RoleEntityDao roleEntityDao;

    public RoleEntity findById(long id) {
        return roleEntityDao.findById(id);
    }

    public PageResult<RoleEntity> list(List<SqlCondition> conditions, SqlPager pager) {
        return roleEntityDao.listPage(conditions, pager);
    }

    /**
     * 根据用户编号查询用户对应角色
     *
     * @param userId
     * @return
     */
    public List<RoleEntity> listByUser(long userId) {
        return roleEntityDao.listByUser(userId);
    }

    @Transactional
    public boolean update(RoleEntity role) {
        return roleEntityDao.update(role);
    }

    @Transactional
    public boolean deleteById(long id) {
        return roleEntityDao.deleteById(id);
    }

    @Autowired
    public void setRoleEntityDao(RoleEntityDao roleEntityDao) {
        this.roleEntityDao = roleEntityDao;
    }

}
